﻿using DimensionsHelper.Common.Contracts.Excel;

namespace DimensionsHelper.Client.WinUi.Helpers;

public static class ColorExtensions
{
    public static Color ToWinUiColor(this ExcelStyleColor color) => Color.FromArgb(255, color.R, color.G, color.B);


    public static ExcelStyleColor ToExcelStyleColor(this Color color)
    {
        if (color.A == 0)
        {
            return ExcelStyleColor.Empty;
        }

        return new ExcelStyleColor(color.R, color.G, color.B);
    }


    public static ExcelStyleColor ToExcelStyleColor(this Color color, IReportService reportService)
    {
        if (color.A != 255)
        {
            reportService.Warn($"颜色 '{color}' 的 Alpha 通道值不是255，已替换为透明（Transparent）颜色");
            return ExcelStyleColor.Empty;
        }

        return new ExcelStyleColor(color.R, color.G, color.B);
    }
}